<?php 

namespace app\Index\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Grounding extends controller
{

	// 新碟上架
	public function grounding()
	{	
		$data = Db::name('tb_special_classify')->where('parent_id',0)->select();
		foreach ($data as $k => $v) {
		    $res = Db::name('tb_special_classify')->where('parent_id',$v['id'])->select();
		    foreach ($res as $a => $b) {
		       $result[$v['name']][] = $b['name'];
		    }
		} 

        $list = Db::name('tb_specials')->order('addtime asc')->field(['name','imgs','id','singer'])->limit(0,4)->select();
		$list2 = Db::name('tb_specials')->order('addtime asc')->paginate(4); 
	    return $this->fetch('grounding/grounding',[
	    		'list'=>$list,
	    		'res'=>$result,
	    		'list2'=>$list2
	    	]);
	}

	public function classify($name)
	{	
		$data = Db::name('tb_special_classify')->where('parent_id',0)->select();
		foreach ($data as $k => $v) {
		    $res = Db::name('tb_special_classify')->where('parent_id',$v['id'])->select();
		    foreach ($res as $a => $b) {
		       $result[$v['name']][] = $b['name'];
		    }
		} 
		$list = Db::name('tb_specials')->order('addtime asc')->field(['name','imgs','id','singer'])->limit(0,4)->select();
		$list2 = Db::name('tb_specials')->where('style',$name)->paginate(4);
		return $this->fetch('grounding/grounding',[
				'list'=>$list,
				'res'=>$result,
				'list2'=>$list2
			]);
	}

	public function album($id)
	{	
		$list = Db::name('tb_specials')
				->alias('sp')
				->join('tb_singers sg','sp.singerid = sg.id')
				->where('sp.id',$id)
				->field('sp.name as spname,sg.name as sgname,dc,icon,imgs,sg.id as sgid')
				->select();

		$res = Db::name('tb_musics')->where('specialid',$id)->select();
		$data = Db::name('tb_specials')->where('singerid',$list[0]['sgid'])->where('id','neq',$id)->select();
		// var_dump($data);
		return $this->fetch('album/album',[
			'list'=>$list,
			'res' =>$res,
			'data'=>$data
			]);
	}

}